<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script type="text/javascript">
      function _comma(number) {
        let negative = ''
        if (number < 0) {
          negative = '-'
          number = Math.abs(number)
        }
        let array = parseInt(number).toString().split('').reverse()
        console.log(array)
        let sign = 0
        let commaArray = []
        for (let i = 0; i < array.length; i++) {
          if (sign === 3) {
            commaArray.push(',')
            sign = 0
          }
          commaArray.push(array[i])
          sign++
        }
        return negative + commaArray.reverse().join('')
      }
      _comma(100345)
      // console.log()
    </script>
  </body>
</html>
